package com.rxyl.love.petdoctor.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rxyl.love.petdoctor.R;
import com.rxyl.love.petdoctor.entity.DistrictEntity;

import java.util.List;

/**
 * Created by dd on 2016/1/13 0013.
 */
public class DistrictAdapter extends BaseAdapter {

    private Context context;
    private List<DistrictEntity> list;

    public DistrictAdapter(Context context, List<DistrictEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_city, null);
            vh = new ViewHolder();
            vh.tv_district = (TextView) convertView.findViewById(R.id.tv_city);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.tv_district.setText(list.get(position).getDistrict_name());
        return convertView;
    }

    class ViewHolder {
        TextView tv_district;
    }
}
